package com.lxx.common;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用返回码
 * @author Administrator
 *
 */
public enum ErrCode {
	
	SUCCESS(0, "成功"),
	FAIL(1, "失败"),
	NOT_LOGGED_IN(2, "无效身份"),  // 未登陆
	CONSTRAINT_FAIL(3, "校验失败"),
	NO_PERMISSION(4, "您无此访问权限"),
	ERROR(9, "服务器内部错误");
	
	
	private int code;
	private String msg;
	
	private ErrCode(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
    public static final Map<Integer, String> lookup = new HashMap<>();  
    
    static {  
        for (ErrCode s : EnumSet.allOf(ErrCode.class)) {  
            lookup.put(s.getCode(), s.getMsg());  
        }
    } 
    
    public Map<String, Object> toMap(){
    	Map<String, Object> ret = new HashMap<>();
    	ret.put("code", getCode());
    	ret.put("msg", getMsg());
    	return ret;
    }

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
